import http from 'axios'

window.__axiosPromiseArr = []
http.defaults.baseURL = '/api'
http.defaults.timeout = 20 * 1000

// 封装统一请求
http.interceptors.request.use(config => {
  return config
}, error => {
  return Promise.reject(error)
})

http.interceptors.response.use(res => {
  return res.data
}, error => {
  return Promise.reject(error)
})

export default {
  post (url, data) {
    return http({
      method: 'post',
      url,
      data
    })
  },
  get (url, params, timeout) {
    return http({
      method: 'get',
      url,
      params,
      timeout
    })
  },
  put (url, data) {
    return http({
      method: 'put',
      url,
      data
    })
  },
  delete (url, data) {
    return http({
      method: 'delete',
      url,
      data
    })
  },
  patch (url, data) {
    return http({
      method: 'patch',
      url,
      data
    })
  }
}